package behavioral.Iterator.outer;

import behavioral.Iterator.IIterator;

public class CustomIterator implements IIterator {

    private CustomAggregate aggregate;
    private int size;
    private int index;

    public CustomIterator(CustomAggregate aggregate) {
        this.aggregate = aggregate;
        this.index = 0;
        this.size = aggregate.size();
    }

    @Override
    public Object first() {
        this.index = 0;
        return this.aggregate.getElement(0);
    }

    @Override
    public Object next() {
        return this.aggregate.getElement(index++);
    }

    @Override
    public boolean hasNext() {
        if (this.index >= this.size) {
            return false;
        }

        return true;
    }

    @Override
    public Object currentObject() {
        return this.aggregate.getElement(index);
    }
}
